import React from 'react'
import { ListView, View } from '@shoutem/ui'
import TextPost from './TextPost'
import ImagePost from './ImagePost'
import VideoPost from './VideoPost'



const renderTextRow = (data, onFavoritePress, onLikePress, level) => (
  <TextPost
    {...data}
    level={level}
    onFavoritePress={onFavoritePress}
    onLikePress={onLikePress}
  />
)

const renderImageRow = (data, onFavoritePress, onLikePress, level) => (
  <ImagePost
    {...data}
    level={level}
    onFavoritePress={onFavoritePress}
    onLikePress={onLikePress}
  />
)

const renderVideoRow = (data, onFavoritePress, onLikePress, level) => (
  <VideoPost
    {...data}
    level={level}
    onFavoritePress={onFavoritePress}
    onLikePress={onLikePress}
  />
)

const FavoritePosts = ({favorites, likes, onFavoritePress, onLikePress, level, tag}) => {
  const datas = level==='favorite' ? favorites : likes
  const renderRows = {
    text: renderTextRow,
    image: renderImageRow,
    video: renderVideoRow
  }
  const renderRow = renderRows[tag]
  return (
    <View style={{marginTop:50, marginBottom:50}}>
      <ListView
        data={datas}
        renderRow={(data) => renderRow(data, onFavoritePress, onLikePress, level)}
      />
    </View>
  )
}

export default FavoritePosts
